<%@ page import="java.util.HashMap,common.CommonUtil,java.util.*,common.*" contentType="text/html; charset=utf-8" %>

<%
UserSession userSession = (UserSession)session.getAttribute("user"); 

String login_id = null;
String user_id = null;
String admin_level = null;
String admin_ent_id = null;

if(userSession!= null){
	login_id = userSession.getLogin_id();
	user_id = userSession.getUser_id();
	admin_level = userSession.getAdmin_level();
	admin_ent_id = userSession.getEnt_id();
}




%>
<jsp:include page="/jsp/common/header.jsp"></jsp:include>
<script language='javascript' src="/js/ajaxutil.js"></script>
<script>

//xml 요청
function getXMLHTTPRequest() {
try {
  req = new XMLHttpRequest();
} catch(err1) {
  try {
  req = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (err2) {
    try {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (err3) {
      req = false;
    } 
  } 
}
return req;
}


function get_login_chk_request(id,ent_id){
  
  var http = getXMLHTTPRequest();
  var myurl = '/speaking.pb?gubun=member&cmd=id_chk&id='+id+'&ent_id='+ent_id;
  myRand = parseInt(Math.random()*999999999999999);
  var modurl = myurl+"&rand="+myRand;  
  http.open("get", modurl, false);
  //http.onreadystatechange = useHttpResponse;
  http.send(null);
  if (http.readyState == 4) {
    return trim(http.responseText);
  }else{
   return "";
  }
} 	

function trim(str){
	str = str.replace(/(^\s*)|(\s*$)/g,"");
	return str;
}

function get_login_chk(){
	var id = document.mainform.login_id.value;
	var ent_id = document.mainform.ent_id.value;
	if(id == ''){
		alert('id 를 입력해주세요');
		document.mainform.login_id.focus();
		return;
	}
	
	if(ent_id == ''){
		alert('기업을 선택해주세요');
		document.mainform.ent_id.focus();
		return;
	}
	
	var id_chk_cnt = get_login_chk_request(id,ent_id);
	
	if(id_chk_cnt==0){
		document.mainform.id_chk.value='Y';
		alert('사용하실 수 있는 id 입니다');
	}else{
		document.mainform.id_chk.value='N';
		alert('사용하실 수 없는 id 입니다');
		document.mainform.login_id.focus();
		document.mainform.login_id.value='';
	}
}

function go_input(){
	var frm = document.mainform;	
	
	if(frm.id_chk.value=='N'){
		alert('id 중복체크 해주세요');
		frm.login_id.focus();
		return;
	}
	if(frm.login_name.value==''){
		alert('이름을 입력 해주세요');
		frm.login_name.focus();
		return;
	}
	if(frm.login_pw.value==''){
		alert('비밀번호 입력 해주세요');
		frm.login_pw.focus();
		return;
	}
	
	if(frm.soc_no1.value=='' || frm.soc_no2.value=='' ){
		alert('주민번호를 입력 해주세요');
		frm.soc_no1.focus();
		return;
	}
	
	frm.post_no.value = frm.post1.value +'-'+ frm.post2.value ;
	
	frm.soc_no.value = frm.soc_no1.value +'-'+ frm.soc_no2.value ;
	frm.email.value = frm.email1.value +'@'+ frm.email2.value ;
	frm.tel_no.value = frm.tel_no1.value +'-'+ frm.tel_no2.value+'-'+ frm.tel_no3.value ;
	frm.cell_no.value = frm.cell_no1.value +'-'+ frm.cell_no2.value +'-'+ frm.cell_no3.value ;
	
	frm.cmd.value='member_insert';
	frm.action = '/speaking.pb';
	frm.target= 'hidden_frm';              
	frm.submit();	
}

function com_pop(url,wid,hei){
	pop=window.open(url,'pop'+wid+hei,'width='+wid+',height='+hei+',status=yes');
	pop.focus();
}

function post_search(){
    frm=document.mainform;
    frm.cmd.value="address";
    var url = "speaking.pb?cmd="+frm.cmd.value;
//  alert(url);
    com_pop(url,500,444);
}

function set_post(post1, post2, addr){
    frm=document.mainform;
    frm.post1.value = post1;
    frm.post2.value = post2;
    frm.addr.value = addr;
}


function go_member(){
	var frm = document.mainform;	
	frm.cmd.value='member_main';
	frm.action = '/speaking.pb';
	frm.target= '_self';              
	frm.submit();	
}

<%if(!admin_level.equals("5")){ %>
function init_member(){
	form = document.mainform;
	setSPSelect(form.ent_id,'', '기업선택', 'ent');
}
window.onload = init_member;
<%}%>
</script>

<jsp:include page="/jsp/common/top.jsp"></jsp:include>
<jsp:include page="/jsp/common/submenu.jsp"><jsp:param name="submenu_id" value="member_main" /><jsp:param name="submenu_idx" value="1" /></jsp:include>

<form name="mainform"  method="post" action = "/speaking.pb" >
	<div id="bodyContainer">
        <div id="contents">
          <jsp:include page="/jsp/common/submenu_list.jsp"><jsp:param name="submenu_id" value="member_main" /><jsp:param name="submenu_idx" value="2" /></jsp:include>
          
          <div class="boxContainer">
            <dl title="회원등록">
              <dt>회원등록</dt>
            </dl>
            <table class="setupTb">
              <%if(!admin_level.equals("5")){ %>
              <tr>
                <th>기업</th>
                <td>
                
	              <select name="ent_id" id="ent_id">
	                  <option value=''>기업선택</option>
	              </select>
	             
                </td>
              </tr>
              <%}else{ %>
              <input type="hidden" name="ent_id" value="<%=admin_ent_id %>">
              <%} %>
              
              <tr>
                <th>ID</th>
                <td><input type="text" name="login_id" id="login_id" style="width:100px"/> <a href="#" onclick="get_login_chk()"><input type="button" value="중복체크" style="width:100px; height:20px"></a></td>
              </tr>
              <tr>
                <th>이름</th>
                <td><input type="text" name="login_name" id="login_name" style="width:100px"/></td>
              </tr>
              <tr>
                <th>비밀번호</th>
                <td><input type="password" name="login_pw" id="login_pw" style="width:100px"/></td>
              </tr>
              <tr>
                <th>비밀번호 확인</th>
                <td><input type="password" name="login_pw2" id="login_pw2" style="width:100px"/></td>
              </tr>
             <tr>
                <th>주민번호</th>
                <td>
                <input type="hidden" name="soc_no" id="soc_no" style="width:100px"/>
                <input type="text" name="soc_no1" id="soc_no1" style="width:100px" maxlength=6/>
                -
                <input type="text" name="soc_no2" id="soc_no2" style="width:100px" maxlength=7/>
                </td>
              </tr>
              
              <tr>
                <th>email</th>
                <td>
                <input type="hidden" name="email" id="email" style="width:100px"/>
                <input type="text" name="email1" id="email1" style="width:100px"/>
                @
                <input type="text" name="email2" id="email2" style="width:100px"/>
                </td>
              </tr>
              <tr>
                <th>연락처</th>
                <td>
                <input type="hidden" name="tel_no" id="tel_no" style="width:50px"/>
                <input type="text" name="tel_no1" id="tel_no1" style="width:50px"/>
                -
                <input type="text" name="tel_no2" id="tel_no2" style="width:50px"/>
                -
                <input type="text" name="tel_no3" id="tel_no3" style="width:50px"/>
                </td>
              </tr>
              <tr>
                <th>휴대폰</th>
                <td>
                <input type="hidden" name="cell_no" id="cell_no" style="width:50px"/>
                <input type="text" name="cell_no1" id="cell_no1" style="width:50px"/>
                -
                <input type="text" name="cell_no2" id="cell_no2" style="width:50px"/>
                -
                <input type="text" name="cell_no3" id="cell_no3" style="width:50px"/>
                </td>
              </tr>        
              
              <tr>
                <th>우편번호</th>
                <td>
                <input type="hidden" name="post_no" id="post_no" style="width:100px"/>
                <input type="text" name="post1" id="post1" style="width:50px"/>
                -
                <input type="text" name="post2" id="post2" style="width:50px"/>
                <img src="/images/btn_ZipCode.gif" title="우편번호" onclick="post_search();" style="cursor:hand" align="absmiddle"/>
                </td>
              </tr> 
              <tr>
                <th>주소</th>
                <td><input type="text" name="addr" id="addr" style="width:200px"/></td>
              </tr> 
              <tr>
                <th>상세주소</th>
                <td><input type="text" name="detail_addr" id="detail_addr" style="width:200px"/></td>
              </tr> 
              <tr>
                <th>비고</th>
                <td><textarea name="etc" rows="5" id="etc" style="width:450px"></textarea></td>
              </tr>   
            </table>
            <p><a href="#" onclick="go_input()"><img src="img/btn_regist.gif" alt="등록" width="49" height="20" /></a> <a href="#" onclick="go_member()"><img src="img/btn_list.gif" alt="목록" width="49" height="20" /></a> </p>
            
          </div>
          
        </div>
      </div>


<input type="hidden" name="cmd" value="">
<input type="hidden" name="user_id" value="<%=user_id %>">
<input type="hidden" name="id_chk" value="N">

</form>

<iframe name='hidden_frm'  width='0' height='0' SCROLLING='AUTO' frameborder='0'></iframe>
<jsp:include page="/jsp/common/footer.jsp"></jsp:include>
<jsp:include page="/jsp/common/bottom.jsp"></jsp:include>
